﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Occ.BRepPrimAPI;
using Occ.gp;
using Occ.TopLoc;
using Occ.TopoDS;
using ZFGK.Addins;
using ZFGK.DocFrame.Utility;
using ZFGK.OCC.Utility;
using ZFGK.OSG.DocUI;
using ZFGK.OSG.DocUI.CmdEnables;
using ZFGK.OSG.DocUI.Utility;
using ZFGK.OSG.UI;
using ZFGK.OsgOcc.Doc.CustomEntity;

namespace OSS.Doc.Cmds.TestCmds
{
    [OnlyDocCmdEnable]
    public class OccTestCmd : IExtendCommand
    {
        /// <summary>
        /// Executes the specified command data.
        /// </summary>
        /// <param name="cmdData">The command data.</param>
        /// <param name="message">The message.</param>
        /// <returns>CmdResult.</returns>
        public CmdResult Execute(ExtendCmdData cmdData, ref string message)
        {
            var docViewForm = cmdData.ViewForm as OsgDocViewForm;
            if (docViewForm == null) return CmdResult.Cancel;

            var osgViewCtrl = docViewForm.View as ZfOsgViewCtrl;
            var actionUtility = osgViewCtrl.ActionUtility;
            var activeDocument = docViewForm.OsgDocViewCtrl.ActiveDocument;

            var t1 = DateTime.Now;
            // 创建板
            var makeBox = new MakeBox(new Pnt(), new Pnt(100, 100, 10));

            // 创建圆柱
            var makeCylinder = new MakeCylinder(7.5, 10);

            // 布尔运算
            var box = makeBox.Solid;
            Shape shape = box;
            // 显示
            var ent = new ZfOsgOccEntity();
            ent.Shape = new Shape(shape);
            activeDocument.PostToModelSpace(ent, activeDocument.ActiveLayer);

            var shapes = new List<Shape>();
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    var solid = makeCylinder.Solid;
                    var trsf = new Trsf();
                    trsf.SetTranslation(new Vec((i + 1) * 20, (j + 1) * 20, 0));
                    solid.Location = new Location(trsf);

                    shape = shape.Cut(solid); 
                    ent.Shape = shape;
                    ent.Update();
                    //shapes.Add(solid);
                }
            }



            var t2 = DateTime.Now;

            MessageBox.Show("耗时：" + (t2 - t1), "测试");

            return CmdResult.Succeed;
        }
    }
}
